<template>
  <div class="app-container" >
    <div>
      <el-row>
        <el-form v-model="studentReportReqVo" :inline="true" class="demo-form-inline" style="padding: 10px 0px;margin-bottom: 10px">
          <el-row :gutter="10" type="flex" justify="center" >

            <el-col class="flex-end" :span="4" :xl="4">
              <el-form-item>
                <span style="font-weight: 700; color: #606266;">患者姓名</span><br>
                <el-input v-model="studentReportReqVo.ptName" placeholder="请输入患者姓名" />
              </el-form-item>
            </el-col>

            <el-col class="flex-end" :span="4" :xl="4">
              <el-form-item>
                <span style="font-weight: 700; color: #606266;">报告编号</span><br>
                <el-input
                  v-model="studentReportReqVo.reportId"
                  placeholder="报告id"
                  oninput="if(value>1000000000000000000)value=1000000000000000000;if(value.length>15)value=value.slice(0,15);if(value<0)value=0"
                  onkeyup="this.value=this.value.replace(/\D/g,'')"
                />
              </el-form-item>
            </el-col>

            <el-col class="flex-end" :span="4" :xl="4">
              <el-form-item>
                <span style="font-weight: 700; color: #606266;">用户名</span><br>
                <el-input v-model="studentReportReqVo.studentUserName" placeholder="学生用户名" />
              </el-form-item>
            </el-col>

            <el-col class="flex-end" :span="4" :xl="4">
              <el-form-item>
                <span style="font-weight: 700; color: #606266;">检查项目</span><br>
                <el-select
                  v-model="studentReportReqVo.ptdtCheckName"
                  placeholder="请选择检查项目"
                  clearable
                  @change="selectkName"
                >
                  <el-option
                    v-for="(item, index) in checkNameList"
                    :key="index"
                    label="检查项目"
                    :label="item"
                    :value="item"
                  />
                </el-select>
              </el-form-item>
            </el-col>

            <el-col class="flex-end" :span="4" :xl="4">
              <el-form-item>
                <span style="font-weight: 700; color: #606266;">报告状态</span><br>
                <el-select
                  v-model="studentReportReqVo.status"
                  placeholder="请选择报告状态"
                  clearable
                  @change="selectStatus()"
                >
                  <el-option
                    v-for="(item, index) in statusS"
                    :key="index"
                    label="报告状态"
                    :label="item"
                    :value="index"
                  />
                </el-select>
              </el-form-item>
            </el-col>

          </el-row>

          <el-row :gutter="20" type="flex" justify="center" style="margin-bottom: 20px;">
            <el-col :span="2"><el-button
              type="primary"
              icon="el-icon-search"
              @click="doSearchbyfrontend"
            >查询</el-button></el-col>
            <el-col :span="10"></el-col>
            <el-col :span="2" ><el-button type="default" @click="resetData()">清空</el-button></el-col>
          </el-row>
        </el-form>
      </el-row>
    </div>
    <div>
      <template class="table">
        <el-table :data="all_total_data.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
         border style="width: 100%" :row-class-name="tableRowClassName">
          <el-table-column prop="reportID" label="报告ID" />
          <el-table-column prop="ptName" label="患者姓名" />
          <el-table-column prop="checkCode" label="检查号" />
          <el-table-column prop="ptdtCheckMachine" label="检查项目类型" />
          <el-table-column show-overflow-tooltip="true" prop="ptdtCheckName" label="检查名字" />
          <el-table-column prop="status" label="报告状态">
            <template slot-scope="scope">
              <span
                :style="{ 'color': scope.row.status === '未完成' ? '#A9A9A9' : scope.row.status === '已完成' ? '#00FF00' : '#FF7F50' }"
              >
                {{ scope.row.status }} </span>

            </template>
          </el-table-column>
          <el-table-column prop="studentUserName" label="学生用户名" />
          <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="small"
                @click.stop="edit(scope.row.ptdeId, scope.row.patientId); testLog(scope.row); seeReport(scope.row.reportID)"
              >查看</el-button>
              <!-- <el-button @click="getReport(scope.row.reportID)" type="text" size="small">查看</el-button> -->
            </template>
          </el-table-column>

        </el-table>
      </template>
      <el-pagination
        background
        layout="prev, pager, next"
        :current-page="queryParams.pageNum"
        :page-size="20"
        :total="all_total_data.length"
        @current-change="changePages"
      />
    </div>

    <!-- 查看---弹窗 -->
    <el-dialog title="查  看" :visible.sync="dialogTableVisible" custom-class="custom-dialog" top="0vh" width="1450px">
      <div class="app-container">
        <div class="app-box">
          <div>
            <div v-loading="loading" class="edit">
              <!-- 左边部分 -->
              <div class="patient-left">
                <!-- 左上 -->
                <div class="patient-message">
                  <div>
                    <div>报告id:{{ report.reportID }}</div>
                    <div>学生用户名:{{ report.studentUserName }}</div>
                    <div>报告创建时间:{{ report.createDate }}</div>
                  </div>
                  <div>
                    <div>检查项目名:{{ report.ptdtCheckName }}</div>
                    <div>检查项目类型:{{ report.ptdtCheckMachine }}</div>

                  </div>
                  <div>
                    <div>状态:{{ status[report.status] }}</div>
                    <div>分数:{{ report.score }}</div>

                  </div>
                </div>

                <!-- 左下 -->
                <div class="patient-content">
                  <div class="patient-contentbox">
                    <div class="bingshi">
                      <div class="title">病人信息</div>
                      <div class="content">
                        <div class="jsbs" style="display:flex; margin-top:10px; ">
                          <div style="width:100px;text-align: right;">病史：</div>
                          <div style="flex:1">{{ report.ptdtBgReadyTxt }}</div>
                        </div>
                        <div class="jsSJ" style="display:flex; margin-top:10px">
                          <div style="width:100px;text-align: right;">检查所见：</div>
                          <div style="flex:1">{{ report.ptdtCheckSjTxt }}</div>
                        </div>
                        <div class="jcYJ" style="display:flex; margin-top:10px">
                          <div style="width:100px;text-align: right;">检查意见：</div>
                          <div style="flex:1">{{ report.ptdtCheckYjTxt }}</div>
                        </div>
                      </div>
                    </div>

                    <div class="suojian">
                      <div class="title">学生报告</div>
                      <div class="content">
                        <el-input
                          v-model="combinedValue"
                          type="textarea"
                          style="width:100%;height:100%"
                          rows="6"
                        />
                      </div>
                    </div>
                    <div class="yijian">
                      <div class="title">教师评价</div>

                      <div class="content">
                        <el-input
                          v-model="combinedValue2"
                          type="textarea"
                          style="width:100%;height:100%"
                          rows="6"
                        />
                      </div>
                    </div>

                    <div class="btn">

                      <el-button type="primary" @click="tijiao(report.status)" :disabled="report.status==='0'">提交报告和评分</el-button>
                      <el-button @click="handlBack">返回</el-button>
                    </div>
                  </div>
                </div>
              </div>

              <!-- 右边部分 -->
              <div class="patient-right">
                <el-tabs v-model="activeName2" type="border-card" @tab-click="handleNodeClick2">
                  <el-tab-pane label="历史" name="first">
                    <el-card>
                      <el-descriptions title="病史" />
                      <div v-for="(item, index) in HistoryVo2" :key="index">
                        <div class="text-item">
                          <span>
                            {{ item.ptdtCheckDate }}
                          </span>
                          <p />
                          <span>
                            {{ item.ptdtBgReadyTxt }}
                          </span>
                        </div>
                      </div>
                    </el-card>
                    <el-card>
                      <el-descriptions title="检查所见" />
                      <div v-for="(item, index) in HistoryVo2" :key="index" class="text-item">
                        <span>
                          {{ item.ptdtCheckDate }}
                        </span>
                        <p />
                        <span>
                          {{ item.ptdtCheckSjTxt }}
                        </span>
                      </div>

                    </el-card>
                    <el-card>
                      <el-descriptions title="检查意见" />
                      <div v-for="(item, index) in HistoryVo2" :key="index" class="text-item">
                        <span>
                          {{ item.ptdtCheckDate }}
                        </span>
                        <p />
                        <span>
                          {{ item.ptdtCheckyjTxt }}
                        </span>
                      </div>
                    </el-card>
                  </el-tab-pane>
                  <el-tab-pane label="截图" name="second">
                    <div class="contents" style="height: 690px; overflow:auto;">
                      <h4 v-if="urls.length === 0" style="text-align: center">数据为空或截图为空</h4>
                      <template v-else>
                        <div v-for="(item, index) in urls" :key="index" style="margin: 5px;">
                          <el-image
                            :src="item.path"
                            lazy
                            @click.native="toggleHighlight(index)"
                          />
                        </div>
                      </template>
                    </div>
                  </el-tab-pane>
                  <el-tab-pane label="模板" name="third">
                    <div class="contents">
                      <el-tree
                        :data="data2"
                        :props="defaultProps2"
                        @node-click="getTemplateInfo2"
                      />
                    </div>
                    <!-- <el-card class="box-card" lable="检查所见" :size="600">
                                                  {{TemplateInfo.libCheckSj}}
                                              </el-card>
                                              <el-card class="box-card" lable="检查意见">
                                                  {{TemplateInfo.libCheckYj}}
                                              </el-card> -->
                  </el-tab-pane>
                  <el-tab-pane label="序列" name="fourth">
                    <div class="contents">
                      <div ref="edits" style="margin: 12px 5px; display: flex;" class="show">
                        <el-button type="success" @click="open">保存</el-button>
                        <el-button type="primary" @click="append">追加</el-button>
<!--                        <el-select v-model="checkFun" style="margin: 0px 10px;" placeholder="请选择">-->
<!--                          <el-option-->
<!--                            v-for="item in funs"-->
<!--                            :key="item.value"-->
<!--                            :label="item.label"-->
<!--                            :value="item.value"-->
<!--                          />-->
<!--                        </el-select>-->
                                                 <el-tooltip effect="dark" content="本地无下载器软件？点击下载！" placement="top">
                                                                              <el-button
type="primary"
                                                        style="float: right"
@click="downloadSoft"
>下载器软件</el-button>
                                                                            </el-tooltip>
                      </div>

<!--                      <el-table-->
<!--                        :data="tableList.slice((currentPage - 1) * pageSize, currentPage * pageSize)"-->
<!--                        style="width: 100%"-->
<!--                        border-->
<!--                        :row-key="getRowKey"-->
<!--                        @selection-change="handleSelectionChange"-->
<!--                      >-->
<!--                        <el-table-column-->
<!--                          type="selection"-->
<!--                          width="55"-->
<!--                          fixed="left"-->
<!--                          :reserve-selection="true"-->
<!--                          :selectable="checkSelectable"-->
<!--                        />-->
<!--                        <el-table-column prop="modality" label="设备" />-->
<!--                        <el-table-column prop="seriesNumber" label="序列号" />-->
<!--                        <el-table-column prop="bodyPartExamined" label="检查部位" min-width="90" />-->
<!--                        <el-table-column prop="seriesNumber" label="图像数" />-->
<!--                        <el-table-column prop="radionuclideTotalDose" label="剂量" />-->
<!--                        <el-table-column prop="radionuclideStartTime" label="注射时间" />-->
<!--                        <el-table-column prop="seriesTime" label="序列时间" min-width="90" />-->
<!--                        <el-table-column prop="manufacturer" label="设备商" min-width="70" />-->
<!--                        <el-table-column prop="modelName" label="设备型号" min-width="90" />-->
<!--                      </el-table>-->


<!--                      <el-table-->
<!--                        :data="tableList"-->
<!--                        style="width: 100%;"-->
<!--                        :row-key="getRowKey"-->
<!--                        :height="241"-->
<!--                        @selection-change="handleSelectionChange"-->
<!--                      >-->
<!--                        <el-table-column-->
<!--                          type="selection"-->
<!--                          width="55"-->
<!--                          fixed="left"-->
<!--                          :reserve-selection="true"-->
<!--                          :selectable="checkSelectable"-->
<!--                       />-->
<!--                        <el-table-column prop="ptdtCheckCode" label="检查号" min-width="150" />-->
<!--&lt;!&ndash;                        <el-table-column prop="seriesDescription" label="检查描述" min-width="150" />&ndash;&gt;-->
<!--                        <el-table-column prop="ptdtName" label="姓名" min-width="100" />-->
<!--                        <el-table-column prop="ptdtAge" label="年龄" />-->
<!--                        <el-table-column prop="ptdtCheckDate2" label="检查日期" min-width="100" />-->
<!--                        <el-table-column prop="ptdtCheckDate3" label="检查时间" min-width="100" />-->
<!--                        <el-table-column prop="ptdtCheckMachine" label="检查类型" min-width="100" />-->
<!--                      </el-table>-->
                      <el-table
                        ref="multipleTable"
                        :data="tableList.slice((currentPage - 1) * pageSize, currentPage * pageSize)"
                        style="width: 100%;margin-bottom: 20px;"
                        border
                        :row-key="getRowKey"
                        :height="487"
                        @selection-change="handleSelectionChange"
                      >
                        <el-table-column
                          type="selection"
                          width="55"
                          fixed="left"
                          :reserve-selection="true"
                        />
                        <el-table-column prop="seriesNumber" label="序列号" />
                        <el-table-column prop="modality" label="设备" />
                        <el-table-column prop="seriesDescription" label="序列描述" />
                        <el-table-column prop="seriesNumber" label="图像数" />
                        <el-table-column prop="bodyPartExamined" label="检查部位" min-width="200" />
                        <el-table-column prop="seriesPat" label="检查号" min-width="150" />
                        <el-table-column prop="seriesDate" label="采集日期" min-width="150" />
                        <el-table-column prop="seriesTime" label="采集时间" min-width="150" />
                        <el-table-column prop="radionuclideTotalDose" label="剂量(mCi)" />
                        <el-table-column prop="manufacturer" label="设备厂商" min-width="70" />
                        <el-table-column prop="modelName" label="设备型号" min-width="90" />
                      </el-table>

                      <el-pagination
                        align="center"
                        style="margin-top: 30px;"
                        :current-page="currentPage"
                        :page-sizes="[1, 5, 10, 20]"
                        :page-size="pageSize"
                        layout="prev, pager, next"
                        background
                        :total="tableList.length"
                        @current-change="handleCurrentChange"
                      />

                    </div>
                  </el-tab-pane>
                </el-tabs>
              </div>
            </div>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import teacher from '@/api/report/teacher'
// UUID组件
import { v4 as uuidv4 } from 'uuid'
export default {
  data() {
    return {
      // 编辑弹窗
      // 用来存放截图
      activeName2: 'first',
      formInline2: {
        user: '111',
        region: ''
      },
      patientInfo2: {},
      checkNameList2: [],
      ptdeId2: '',
      patientId2: '',
      ptdtOperDatetime2: '',
      PtPatientVo2: {},
      defaultProps2: {
        label: 'label',
        children: 'children'
      },
      // 截图
      imgs: [],
      url: {},
      urls: [],
      allimgnumber: '',
      selectimgnumber: 0,
      data2: [],
      DetailslList2: {},
      Survey2: {},
      HistoryVo2: [],
      TemplateInfo2: {},
      //
      studyInsta: null,
      studyInsta2: '',
      tableList: [],
      currentPage: 1,
      pageSize: 14,
      select_num: 0,
      // 选择序列
      studentArr: [],
      checkAll: false,

      isIndeterminate: true,
      select_list: [],

      checkFun: '',
      funs: [
        {
          label: 'PETMR2D',
          value: '1'
        },
        {
          label: 'PETMR3D',
          value: '2'
        },
        {
          label: 'PETCT',
          value: '3'
        },
        {
          label: 'NM2D',
          value: '4'
        },
        {
          label: 'PTFC',
          value: '5'
        }
      ],
      multipleSelection: [],
      activeName: 'first',
      tabPosition: 'top',
      // 返回的学生对象
      studentReportListPageResVo: [],
      // 请求学生报告对象
      studentReportReqVo: {},
      // 检查项目名
      checkNameList: [],
      // 完成状态
      completeList: [],
      // 总数
      total: 0,
      //前端分页
      all_total_data : [],
      // 分页参数
      queryParams: {
        pageNum: 1,
        pageSize: 1000000
      },
      // 状态
      statusS: ['未完成', '已完成', '已批改'],

      dialogTableVisible: false, // 查看---弹窗控制

      // 报告详情数据
      textarea1: 'dnjoiksadnsnnnnnnnnnnnnnnnnnnnnnnnnnnklasdnklasndkaslndkdnkslandksladnkslandklasdnksal',
      reportId: this.$route.query.id,
      report: {},
      reportObj: '',
      status: ['未完成', '已完成', '已批改'],
      updateStatus: '2',
      //
      cdoe: '',
      // 病史
      HistoryVo: [],
      activeName: 'first',
      activeName6: 'first',
      defaultProps: {
        label: 'label',
        children: 'children'
      },
      data: [],
      TemplateInfo: {},
      tabIndex: 1, // tab切换索引
      ptdeId: '-1222'
    }
  },
  computed: {
    combinedValue: {
      get() {
        // 返回需要绑定的多个属性的组合值
        return this.report.jcProReadyTxt + this.report.jcReadyTxt + this.report.jcSjTxt + this.report.jcYjTxt
      },
      set(value) {
        const length = value.length
        const partLength = Math.floor(length / 4) // 每个部分的长度
        this.report.jcProReadyTxt = value.slice(0, partLength)
        this.report.jcReadyTxt = value.slice(partLength, 2 * partLength)
        this.report.jcSjTxt = value.slice(2 * partLength, 3 * partLength)
        this.report.jcYjTxt = value.slice(3 * partLength)
      }
    },
    combinedValue2: {
      get() {
        // 返回需要绑定的多个属性的组合值
        return this.report.checkProReady + this.report.checkReady + this.report.checkSee + this.report.checkOpinion
      },
      set(value) {
        const length = value.length
        const partLength = Math.floor(length / 4) // 每个部分的长度
        this.report.checkProReady = value.slice(0, partLength)
        this.report.checkReady = value.slice(partLength, 2 * partLength)
        this.report.checkSee = value.slice(2 * partLength, 3 * partLength)
        this.report.checkOpinion = value.slice(3 * partLength)
      }
    }
  },
  created() {
    this.doSearch()
    this.selectkName()
    this.selectStatus()
  },
  methods: {
    handlBack(){
      this.dialogTableVisible=false
    },
    // 图像添加高亮
    toggleHighlight(index) {
      this.urls[index].selected = !this.urls[index].selected
      this.selectimgnumber1()
      this.imgchange()
      this.imgchange()
      // console.log(this.urls[index])
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.status === '已完成') {
        return 'check-row'
      } else if (row.status === '已批改') {
        return 'finish-row'
      }
      return 'no-row'
    },

    doSearchbyfrontend(){
      this.doSearch()
      let new_alll_total_data=[]

      if(this.studentReportReqVo.ptName!=='' && this.studentReportReqVo.ptName!==null && this.studentReportReqVo.ptName!==undefined){
      new_alll_total_data.push( this.all_total_data.filter(item=>{
          return item.ptName===this.studentReportReqVo.ptName
        })
      )
      }
      if(this.studentReportReqVo.reportId!=='' && this.studentReportReqVo.reportId!==null && this.studentReportReqVo.reportId!==undefined){
        new_alll_total_data.push( this.all_total_data.filter(item=>{
          return item.reportID===this.studentReportReqVo.reportId
        })
      )
      }
      if(this.studentReportReqVo.studentUserName!=='' && this.studentReportReqVo.studentUserName!==null && this.studentReportReqVo.studentUserName!==undefined){
        new_alll_total_data.push( this.all_total_data.filter(item=>{
          return item.studentUserName===this.studentReportReqVo.studentUserName
        })
      )
      }
      if(this.studentReportReqVo.ptdtCheckName!=='' && this.studentReportReqVo.ptdtCheckName!==null && this.studentReportReqVo.ptdtCheckName!==undefined){
        new_alll_total_data.push( this.all_total_data.filter(item=>{
          return item.ptdtCheckName === this.studentReportReqVo.ptdtCheckName
        })
      )
      }
      if(this.studentReportReqVo.status!=='' && this.studentReportReqVo.status!==null && this.studentReportReqVo.status!==undefined){
        new_alll_total_data.push( this.all_total_data.filter(item=>{

          if(item.status=='未完成'){

            return item.status === '未完成'
          }else if(item.status=='已完成'){

            return item.status === '已完成'
          }else if(item.status=='已批改'){

           return item.status === '已批改'
          }
        })
      )
      }
      // while (this.all_total_data.length) {
      //   this.$set(this.all_total_data, 0, null);
      //   this.all_total_data.shift();
      // }
      console.log(new_alll_total_data)
      this.all_total_data = new_alll_total_data[0]
      // new_alll_total_data.forEach((item, index) => {
      //   this.$set(this.all_total_data, index, item);
      // });

    },
    // 查询学生报告集合
    doSearch() {
      teacher.getStudentReport({}, this.queryParams).then(response => {
        console.log(response.rows)
        const uniqueRows = [];
        const seen = new Set();
        response.rows.forEach(item => {
          const { reportID, createDate,...rest } = item;
          const key = JSON.stringify(rest);
          if (!seen.has(key)) {
            seen.add(key);
            uniqueRows.push(item);
          }
        });
        uniqueRows.forEach(item => {
          if (item.status == '0') {
            item.status = '未完成'
          } else if (item.status == '1') {
            item.status = '已完成'
          } else if (item.status == '2') {
            item.status = '已批改'
          }
        })
        console.log(uniqueRows)
        this.total = uniqueRows.length
        this.all_total_data = uniqueRows
        // this.studentReportListPageResVo =uniqueRows
        // this.studentReportListPageResVo.forEach(item => {
        //   if (item.status == '0') {
        //     item.status = '未完成'
        //   } else if (item.status == '1') {
        //     item.status = '已完成'
        //   } else if (item.status == '2') {
        //     item.status = '已批改'
        //   }
        // })
        // this.total = response.total
      })
    },
    // 选择页数
    changePages(e) {
      this.currentPage = e;
      // this.$set(this.queryParams, 'pageNum', e)
      // this.doSearch()
    },
    // 清空查询条件
    resetData() {
      this.studentReportReqVo = {
        pageNum: 1,
        PageSize: 5000,
      }
    },
    // 下拉检查项目名
    selectkName() {
      teacher.getDropDownCheckName().then(response => {
        this.checkNameList = response.data || {}
      })
    },
    // 报告状态
    selectStatus() {
      teacher.getSelectStatus().then(response => {
        this.completeList = response.data
      })
    },
    // 查询学生报告
    getReport(reportID) {
      this.$router.push({ path: `/teacher/report`, query: { id: reportID }})
    },

    // 报告详情数据
    // 获取报告详情
    getReport(reportObj) {
      teacher.getReport(reportObj).then(response => {
        this.report = response.data
      }).then(response => {
        this.getBgReady()
      })
    },
    // 新增/修改评价
    insertComment() {
      if (this.report.status == '1') {
        if (this.report.checkSee == null) {
          this.report.checkSee = ''
        }
        if (this.report.checkProReady == null) {
          this.report.checkProReady = ''
        }
        if (this.report.checkReady == null) {
          this.report.checkReady = ''
        }
        if (this.report.checkOpinion == null) {
          this.report.checkOpinion = ''
        }
        teacher.insertComment(this.report, this.updateStatus).then(response => {
          this.cdoe = response.code
          if (this.cdoe == 200) {
            this.code = ''
          }
        })
      }
      if (this.report.status == '2') {
        teacher.updateComment(this.report).then(response => {
          this.cdoe = response.code
          if (this.cdoe == 200) {
            this.code = ''
          }
        })
      }
      if (this.report.status == '0') {
        this.$message('请勿批改学生未完成的报告')
      }
    },

    // 点击节点触发
    getTemplateInfo(e) {
      if (e.children == null) {
        teacher.getTemplateInfo(e.id, e.pid).then(
          response => {
            this.TemplateInfo = response.data || {}
            this.report.checkSee = this.TemplateInfo.libCheckSj
            this.report.checkOpinion = this.TemplateInfo.libCheckYj
          }
        )
      }
    },
    handleClick6(tab, event) {
      console.log(tab, event)
    },
    // 标签页切换触发
    handleNodeClick(e) {
      switch (this.activeName) {
        case 'first':
          if (this.report != null) {
            this.getBgReady()
          }
          break
        case 'second':
          console.log('second')
          break
        case 'third':
          teacher.getTemplate().then(response => {
            this.data = response.data.public
          })
          break
        case 'four':
          console.log('fourth')
          break
      }
    },

    // 历史
    getBgReady() {
      teacher.getHistory(this.report.patientId, this.ptdeId).then(
        response => {
          this.HistoryVo = response.data || {}
        }
      )
    },
    // ----------------------------------------------编辑弹窗-------------------------------------------

    edit(ptdeId, patientId) {
      this.ptdeId2 = ptdeId
      this.patientId2 = patientId
      this.editDialogVisible = true
      this.getDropDownCheckName2()
      this.getPatient2(this.ptdeId2)
      this.getBgReady2()
    },
    // 测试用代码
    testLog(row) {
      this.studyInsta2 = row.studyInsta
      console.log(this.studyInsta2)
    },
    // 0702 保存按钮点击事件
    open() {
      if(this.select_list.length <=0){
        return this.$message.info("请先勾选选择序列图像")
      }
      const fn_type = 'PTFC'
      const action = 'open'
      this.invokeSoftware(fn_type, action)
    },
    downloadSoft() {
      this.$confirm('是否下载下载器软件？')
        .then(_ => {
          setTimeout(() => {
            window.location.href = `http://120.27.23.108:8087/tspetsetup1.0.3.exe`
          }, 3000)
          window.location.href = `http://120.27.23.108:8087/融合软件[TEST].x64.20230810-FULL.rar`
        })
        .catch(_ => { })
    },
    append() {
      if(this.select_list.length <=0){
        return this.$message.info("请先勾选选择序列图像")
      }
      const fn_type = 'PTFC'
      const action = 'append'
      this.invokeSoftware(fn_type, action)
    },
    // 请求信息
    invokeSoftware(fn_type, action) {
      let uuid01 = uuidv4()
      uuid01 = uuid01.replace(/-/g, '')
      console.log('uuid01 = ' + uuid01)
      const msg = {
        function: fn_type,
        action: action,
        uuid: uuid01,
        series: this.select_list
      }
      console.log(JSON.stringify(msg))
      teacher.getResponseStatus(JSON.stringify(msg)).then(response => {
        console.log('teacher.getResponseStatus调用')
        if (response.code == 200) {
          console.log('ok')
          try {
            // 调试用

            // throw '未下载';
            window.location.href = `tspet://${action}/${uuid01}`
            console.log('href ok')
          } catch (error) {
            console.log(' error===> ' + error)
            // 下载对应软件
            setTimeout(() => {
              window.location.href = `http://172.20.128.6:8087/tspetsetup1.0.3.exe`
            }, 3000)
            window.location.href = `http://172.20.128.6:8087/融合软件[TEST].x64.20230810-FULL.rar`
          }
        }
      })
    },

    // 确保只能选中0,1,2个选项
    checkSelectable(row) {
      // console.log(row);
      return this.multipleSelection.length < 2 ||
                (row.seriesInst == this.select_list[0].seriesInst ||
                    row.seriesInst == this.select_list[1].seriesInst)
    },
    // 改变多选框状态
    handleSelectionChange(val) {
      console.log('改变多选框状态')
      this.multipleSelection = val
      // 清空 select_list
      this.select_list = []
      val.forEach(element => {
        this.select_list.push(element)
      })
      console.log(this.select_list)
      console.log(this.multipleSelection)
      this.isShow()
    },
    // 改变显示状态
    isShow() {
      // 选中弹出样式
      if (this.multipleSelection.length > 0) {
        console.log(this.multipleSelection.length)
        this.$refs.edits.style.visibility = 'visible'
      } else {
        this.$refs.edits.style.visibility = 'hidden'
      }
    },
    // 指定一个key标识这一行的数据
    getRowKey(row) {
      // console.log(row);
      return row.seriesNumber
    },

    // 当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`)
      this.currentPage = val
    },

    editHandleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => { })
    },

    // 点击节点触发
    getTemplateInfo2(e) {
      if (e.children == null) {
        teacher.getTemplateInfo(e.id, e.pid).then(
          response => {
            this.TemplateInfo2 = response.data || {}
            this.PtPatientVo2.ptdtCheckSjTxt = this.TemplateInfo2.libCheckSj
            this.PtPatientVo2.ptdtCheckyjTxt = this.TemplateInfo2.libCheckYj
          }
        )
      }
    },
    getBgReady2() {
      teacher.getHistory(this.patientId2, this.ptdeId2).then(
        response => {
          this.HistoryVo2 = response.data || {}
          console.log('HistoryVo2:')
          console.log(this.HistoryVo2)
        }
      )
    },
    // 标签页切换触发
     handleNodeClick2(e) {
       switch (this.activeName2) {
        case 'first':
          this.getBgReady2()
          break
        case 'second':
          console.log('second')
          teacher.getAllImgs(this.ptdeId2).then(response => {
            if (typeof response.data === 'number') {
              this.urls = []
              this.allimgnumber = 0
              this.selectimgnumber = 0
            } else {
              this.urls = []
              for (let i = 0; i < response.data.length; i++) {
                // 依照el-image需要的数据格式修改data对象到this.url中
                this.url.completePath = response.data[i].completePath
                this.url.path = 'data:image/jpeg;base64,' + response.data[i].imageBase64
                this.url.imageID = response.data[i].imageID
                this.url.imageDescription = response.data[i].imageDescription
                this.url.selected = !response.data[i].number
                // 修改好的对象push进对象数组this.urls中
                this.urls.push(this.url)
                this.url = {}
                this.allimgnumber = response.data.length
                this.selectimgnumber1()

              }
              console.log(this.urls)

            }

          })
          // teacher.getAllImgs(this.ptdeId2).then(response => {
          //   console.log(response.msg)
          //   console.log(response.data)
          //   this.imgs = response.data
          //   for (let i = 0; i < 20; i++) {
          //     if(response.data[i].imageBase64!== null){
          //       this.imgs.push(response.data[i])
          //     }
          //
          //   }
          //
          //   if (this.isFirst) {
          //
          //   } else {
          //     this.isFirst = true
          //     for (let i = 0; i < 10; i++) {
          //       // 显示数据是否获取正常
          //       console.log(response.data[0])
          //       // 依照el-image需要的数据格式修改data对象到this.url中
          //       this.url = 'http://172.20.128.6:8089' + response.data[i]
          //       console.log(this.url)
          //       // 修改好的对象push进对象数组this.urls中
          //       this.urls.push(this.url)
          //       this.url = ''
          //     }
          //   }
          //   // 展示数组
          //   console.log(this.urls)
          // })
          break
        case 'third':
          teacher.getTemplate().then(response => {
            this.data2 = response.data.public
          })
          break
        case 'fourth':
          console.log('four 已触发')
          // console.log(this.studyInsta2)
          const tempData = {
            ptdeid: this.ptdeId2,
            nameList: [],
          }
          teacher.getSequence1(this.studyInsta2).then(
            res=>{
              this.$nextTick(()=>{
                this.tableList= res.data
                console.log(this.tableList)
              })
            }
          )

          break
      }
    },
    changeCheckName2(e) {
      this.$set(this.PtPatientVo2, 'ptdtCheckName', e)
    },
    getDropDownCheckName2() {
      teacher.getDropDownCheckName().then(response => {
        this.checkNameList2 = response.data
      })
    },
    selectimgnumber1() {
      this.selectimgnumber = 0
      this.urls.forEach(url => {
        this.selectimgnumber += url.selected
      })
    },
    // 获取患者信息
    getPatient2(ptdeId2) {
      //  this.list.forEach(item =>{
      //   if(ptdeId2 == item.ptdeId){
      //     this.PtPatientVo2 = item;
      //     console.log(this.PtPatientVo2);
      //   }
      // })
      teacher.getPatient(ptdeId2).then(response => {
        this.PtPatientVo2 = response.data
      })
    },
    // 保存
    onSubmit2() {
      this.$confirm('确定保存, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        teacher.updatePatient(this.PtPatientVo2)
          .then(response => {
            this.$message({
              type: 'success',
              message: '保存成功!'
            })
            this.editDialogVisible = false
            this.getList()
          })
      })
    },

    // 提交
    tijiao(status) {
      // console.log(status)
      if(status === '1'){
        return this.$message.info("当前报告已完成，无法评分！")
      }
      this.$prompt('请输入评分！确定之后会提交评分和评价', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /^(0|[1-9]\d?|100)$/,
        inputErrorMessage: '请输入0-100的分数'
      }).then((val) => {
        this.report.score = val.value
        this.insertComment()
        this.$message({
          type: 'success',
          message: '你提交了评价和分数！'
        })
        this.doSearch()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消评价和评分'
        })
      })
    },

    seeReport(id) { // 详情报告弹窗
      this.dialogTableVisible = true
      this.getReport(id)
    }
  }
}

</script>

<style lang="scss" scoped>
.el-table{
  margin-bottom: 20px;
}
$border: 1px solid #ececec;

div {
    box-sizing: border-box;
}

.edit {
    box-sizing: border-box;
    margin: 0px auto;
    display: flex;

    //左边
    .patient-left {
        display: block;
        width: 900px;

        .patient-message {
            //左边头部
            width: 95%;
            height: 100px;
            margin-left: 20px;
            display: flex;
            flex-wrap: wrap;
            justify-content: start;
            align-items: center;
            border-radius: 15px;
            background: #e5f5ff;
            box-shadow: 7px 7px 15px #bebebe, -3px -3px 7px #ffffff;
            // border: 1px groove rgba(150, 215, 255, 0.242);
            border: $border;
            padding: 18px 22px;
            box-sizing: border-box;

            div {
                padding: 0px 16px;

            }
        }

        .patient-content {
            margin-left: 20px;
            margin-top: 15px;
            width: 95%;
            border: 1px solid #ececec;
            background: #ffffff;
            box-shadow: 7px 7px 15px #bebebe, -7px -7px 15px #ffffff;

            .patient-contentbox {
                height: 100%;
                margin: 15px;
                // box-shadow: 4px 4px 25px 2px rgba(156, 152, 152, 0.308);
                overflow-y: auto;

                ::v-deep .el-textarea__inner {
                    // background-color: rgba(150, 215, 255, 0.242);
                    box-shadow: 7px 7px 15px #bebebe;
                    backdrop-filter: blur(7px);
                    border-radius: 15px;
                    background: #ffffff;

                    transition: all 0.3s;
                    cursor: pointer;
                }

            }

            .btn {
                text-align: center;
                height: 72px;
                line-height: 72px;
            }
        }

    }

    .bingshi,
    .suojian,
    .yijian {
        border: $border;
        margin-top: 10px;

        .title {
            background-color: #e5f5ff;
            height: 50px;
            line-height: 50px;
            padding-left: 20px;
            font-weight: bold;
            font-size: 18px;
            border-bottom: $border;
            margin: 3px 0px;
        }

        :deep(textarea) {
            border: none;
        }
    }
}

.patient-right {
    width: 550px;

    background-color: #ffffff;
    border: $border;
    padding: 10px;
    backdrop-filter: blur(7px);
    background-color: rgba(255, 255, 255, 0.5);
    background: #ffffff;
    box-shadow: 7px 7px 15px #bebebe, -7px -7px 8px #ebe7e7;
}
</style>
<style>
.bingshi .content {
    height: 150px;
    /* 设置固定高度 */
    overflow-y: scroll;
    /* 添加垂直滚动条 */
}

.el-dialog__header {
    border-bottom: 3px solid #e3e8ee;
    background-color: #E5F5FF;

    font-size: 20px;

}

.el-table .cell {
    white-space: nowrap;
    /* word-wrap: break-word;
            word-break: break-all; */
}

.el-table .check-row {
    background: #E7FAF0;
}

.el-table .finish-row {
    background: #FFEDED;
}

.el-table .no-row {
    background: #E8F4FF;
}

.custom-dialog {
    background-color: #F5F7FA;
    left: 100px;
    top: -6vh;

}
</style>

<style lang="scss" scoped>
/*.app-container {
    $border: 1px solid #ECECEC;

    .active {
        color: #409eff;
    }

    .patient-message {
        border: $border;
        background-color: #ffffff;

        >div {
            display: inline-block;
            padding: 15px;
        }
    }

    .app-box {
        width: 100%;
        min-height: 1500px;
        display: flex;
        overflow: hidden;
    }

    .app-left {
        width: 100%;
        height: 100%;
    }}

    /*.pingfen {
        position: absolute;
        right: 20px;
        top: 50%;
        transform: translateY(-50%);
        background-color: #409eff;
        height: 38px;
        line-height: 38px;
        width: 150px;
        text-align: center;
        color: white;
        border-radius: 5px;
        cursor: pointer;

    }

    // tabs切换卡
    .tab_tit {
        list-style: none;
        display: flex;
        background-color: white;
        margin: 0;
        border: $border;
        position: relative;

        li {
            margin-right: 30px;
            line-height: 60px;
            cursor: pointer;
        }

        .pingfen {
            position: absolute;
            right: 20px;
            top: 50%;
            transform: translateY(-50%);
            background-color: #409eff;
            height: 38px;
            line-height: 38px;
            width: 150px;
            text-align: center;
            color: white;
            border-radius: 5px;
            cursor: pointer;

        }
    }

    .tab_con {
        padding: 16px;
        background-color: white;
        border: $border;
        box-sizing: border-box;

        .tav_content {
            height: 720px;
            width: 90%;
            border: $border;

            .content {
                height: 500px;
                width: 90%;
            }
        }
    }
}

.xinxi {
            height: 440px;
            display: flex;

            .bingren {
                width: 130px;
                box-sizing: border-box;
                text-align: center;
                line-height: 440px;
                border: $border;
                background-color: #fafafc;
            }

            .bingrenXinxi2 {
                flex: 1;
                border: $border;

                ::v-deep textarea {
                    width: 100%;
                    height: 100%;
                    border: none;
                    background-color: white;
                    line-height: 30px;
                    resize: none;
                    color: black;
                    cursor: default;
                }

            }

            .bingrenXinxi1 {
                flex: 1;
                border: $border;

                ::v-deep textarea {
                    width: 100%;
                    height: 100%;
                    background-color: white;
                    line-height: 30px;
                    resize: none;
                    color: black;
                }
            }
        }

    }

    div::-webkit-scrollbar {

        width: 10px;

        height: 1px;
    }

    div::-webkit-scrollbar-thumb {

        border-radius: 10px;
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        background: #535353;
    }

    div::-webkit-scrollbar-track {

        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        border-radius: 10px;
        background: #ededed;
    }

    .el-card-define {
        min-height: 100%;
        height: 100%;
    }

    .el-card-define>>>.el-card__body {
        height: 100%;
    }

    .box ::v-deep .el-card,
    ::v-deep .is-always-shadow,
    ::v-deep .el-card__body {
        height: 100%;
    }
}

::v-deep .el-dialog__body {
    padding: 0;
}

.bingrenXinxi2 {
    border-radius: 5px;
    background: #ffffff;
    box-shadow: 7px 7px 15px #bebebe,
        -7px -7px 15px #ffffff;
}

.bingrenXinxi:hover{
  box-shadow: 35px 35px 68px 0px rgba(157, 177, 255, 0.5);
}
.bingrenXinxi2:active{
    transform: scale(0.95);
  border: 1px solid rgb(24, 144, 255);
}*/
</style>
